//creates rect object
sCanvas.fn.circ = function() {
	if (arguments.length !== 1 && arguments.length !== 3) {
		throw new Error("Wrong arguments was passed to circ().");
	}
	
	var attrs,
		obj = new CanvasCirc(this);
	
	if (arguments.length === 1) {
		attrs = arguments[0];
	} else {
		attrs = {
			x: arguments[0],
			y: arguments[1],
			radius: arguments[2]
		};
	}

	obj.attr(attrs);

	this.register(obj);
	this.autorepaint();
	return obj;
};



var CanvasCirc = function(sc) {
	this.init(sc);
	this.addSupportedAttr("radius");
	this.addAnimatableAttr("radius");
	this.initAttrs();
	return this;
};

CanvasCirc.prototype = new sCanvasObject();

CanvasCirc.prototype.createFillPath = function(cx) {
	cx.save();
	cx.translate(this.attrs.x, this.attrs.y);
	cx.rotate(this.attrs.rotation);
	cx.beginPath();
	cx.arc(
		-this.origin.x,
		-this.origin.y,
		this.attrs.radius,
		0,
		2 * Math.PI,
		false);
	cx.closePath();
	cx.restore();
};

CanvasCirc.prototype.createStrokePath = function(cx) {
	this.createFillPath(cx);
};

CanvasCirc.prototype.createPointInPath = function(cx) {
	this.createFillPath(cx);
};

CanvasCirc.prototype.box = function() {
	var center;
	if (this.attrs.rotation === 0) {
		return {
			top: this.attrs.y - this.origin.y - this.attrs.radius,
			right: this.attrs.x - this.origin.x + this.attrs.radius,
			bottom: this.attrs.y - this.origin.y + this.attrs.radius,
			left: this.attrs.x - this.origin.x - this.attrs.radius,
			width: 2 * this.attrs.radius,
			height: 2 * this.attrs.radius
		};
	} else {
		center = this.rotatedCenter();
		return {
			top: Math.round(center.y - this.attrs.radius),
			right: Math.round(center.x + this.attrs.radius),
			bottom: Math.round(center.y + this.attrs.radius),
			left: Math.round(center.x - this.attrs.radius),
			width: 2 * this.attrs.radius,
			height: 2 * this.attrs.radius
		};
	}
};